<style scoped>

</style>

<template>
    <div class="modify-inquiry-sheet-page">
        <el-form :inline="true" :model="formInline" class="demo-form-inline" style="border-bottom:1px solid #ccc;">
            <el-form-item label="法人名称" prop="legalPersonName" :rules="[{ required: true, message: '法人名称不能为空'}]" :label-width="labelWidth" v-if="!powerFlag">
                <el-select size="mini" disabled  v-model="formInline.legalPersonName" placeholder="请选择">
                    <el-option v-for="(legalPerson,index) in legalPersonDropDown" :key="index" :label="legalPerson.legalPersonName" :value="legalPerson.legalPersonName">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="报价单号" class="selectMB10" :label-width="labelWidth">
                <el-input size="mini" disabled v-model="formInline.quotationNumber" placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="报价日期" class="selectMB10" :label-width="labelWidth">
                <el-input size="mini" disabled v-model="formInline.createTime" placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="报价人员" class="selectMB10" :label-width="labelWidth">
                <el-input size="mini" disabled v-model="formInline.bidderName" placeholder=""></el-input>
            </el-form-item>

            <el-form-item label="报价类型" prop="biddingType" :rules="[{ required: true, message: '报价类型不能为空'}]" :label-width="labelWidth">
                <el-select size="mini" v-model="formInline.biddingTypeName" placeholder="请选择">
                    <el-option v-for="(biddingType,index) in selectDropdown.type" :key="index" :label="biddingType.label" :value="biddingType.value"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="报价币别" prop="currencyCode"  :rules="[{ required: true, message: '报价币别不能为空'}]" :label-width="labelWidth">
                <el-select size="mini" v-model="formInline.currencyCode" placeholder="请选择" @change="selectCurrencyCode">
                    <el-option v-for="(inquiryCurrency,index) in selectDropdown.currencyCode" :key="index" :label="inquiryCurrency.label" :value="inquiryCurrency.value"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="报价单位" prop="vendor" :rules="[{ required: true, message: '报价单位不能为空'}]" :label-width="labelWidth">
                <el-select size="mini" disabled v-model="formInline.vendor" placeholder="请选择">
                    <el-option v-for="(vendor,index) in formInline.selectDropdown" :key="index" :label="vendor.partnerName" :value="vendor.partnerCode"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="报价对象" v-if="powerFlag && qObjDropDownValue.length==1" :label-width="labelWidth">
                <el-input size="mini" disabled v-model="formInline.legalPersonName"></el-input>
            </el-form-item>
             <el-form-item label="报价对象"  v-else-if="powerFlag" prop="legalPersonId"  :rules="[{ required: true, message: '报价对象不能为空'}]" :label-width="labelWidth">
                <el-select size="mini" v-model="formInline.legalPersonId" placeholder="请选择" @change="selectedQObj">
                    <el-option v-for="(qObj,index) in qObjDropDownValue" :key="index" :label="qObj.legalPersonName" :value="qObj.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item prop="exchangeRate" label="汇率" :rules="[{ required: true, message: '汇率不能为空'}]" :label-width="labelWidth">
                <el-input size="mini"  v-model.number="formInline.exchangeRate" placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="金额是否含税" prop="isTax"  :rules="[{ required: true, message: '此项为必填项'}]" :label-width="labelWidth100">
                <el-select size="mini" v-model="formInline.isTaxName" placeholder="请选择" @change="changeTax">
                    <el-option v-for="(isIncludeTax,index) in selectDropdown.isTax" :key="index" :label="isIncludeTax.label" :value="isIncludeTax.value"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="报价生效日期" prop="startTime"  :rules="[{ required: true, message: '报价生效日期不能为空'}]" :label-width="labelWidth100">
                <el-date-picker type="date" size="mini" :editable="false" v-model="formInline.startTime" placeholder="选择报价生效日期" @change="selectedStartTime"></el-date-picker>
                <!-- :picker-options="InquiryBeginsDate" readonly-->
            </el-form-item>
            <el-form-item label="报价失效日期" prop="endTime"  :rules="[{ required: true, message: '报价失效日期不能为空'}]" :label-width="labelWidth100">
                <el-date-picker type="date" size="mini" :editable="false" v-model="formInline.endTime" placeholder="选择报价失效日期" @change="selectedEndTime"></el-date-picker>
                <!-- :picker-options="InquiryEndDate" -->
            </el-form-item>
            <el-form-item label="报价总数量" :label-width="labelWidth100">
                <el-input size="mini" disabled placeholder="" v-model="formInline.totalQuantityQuoted"></el-input>
            </el-form-item>
            <el-form-item label="报价不含税总金额" :label-width="labelWidth120">
                <el-input size="mini" disabled placeholder="" v-model="formInline.totalQuotedPrice"></el-input>
            </el-form-item>
            <el-form-item label="报价含税总金额" :label-width="labelWidth120">
                <el-input size="mini" disabled placeholder="" v-model="formInline.totalQuotedTaxPrice"></el-input>
            </el-form-item>
            <el-form-item class="selectMB10">
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="save(10)">保存</el-button>
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" v-if="formInline.inquiryStatus==20" disabled @click="onSubmit(20)">提交</el-button>
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" v-else @click="onSubmit(20)">提交</el-button>
            </el-form-item>
        </el-form>
        <!--待报价明细表格-->
        <label class="default-label">待报价明细：</label>
      <!--  <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="leadingInMask">导入</el-button>
        <el-button class="bolder outsideBtnBS" size="mini" type="danger"  @click="addSpare">导出</el-button>-->
        <el-table :data="inquiryDetailsData" border style="width: 100%;" v-loading.body="loading" element-loading-text="拼命加载中">
            <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
            <el-table-column prop="spareCoding" label="备件编码" header-align="center"  show-overflow-tooltip></el-table-column>
            <el-table-column prop="spareName" label="备件名称" header-align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="measurementUnit" label="计量单位" header-align="center" width="100" show-overflow-tooltip></el-table-column>
            <el-table-column prop="quotedQuantity" label="报价数量" header-align="center" width="100">
                <!--<template scope="scope">
                    <el-input size="mini"  v-model.number="scope.row.quotedQuantity" placeholder=""  @change="InputInquiryQty(scope.$index, scope.row,$event)"></el-input>
                </template>-->
            </el-table-column>
            <el-table-column prop="currencyCodeWord" label="币别" header-align="center" width="80"  show-overflow-tooltip></el-table-column>
            <!--含税单价金额-->
            <el-table-column prop="includingTaxPrice" label="含税单价金额" header-align="center" width="100">
                <template scope="scope">
                    <el-input size="mini"  v-model.number="scope.row.includingTaxPrice" :disabled="formInline.isTaxName=='不含税'" v-if="!isShow" @change="inputTaxPrice(scope.$index, scope.row)"></el-input>
                    <el-input size="mini"  v-model.number="scope.row.includingTaxPrice" :disabled="isTaxShow!=1" v-else @change="inputTaxPrice(scope.$index, scope.row)"></el-input>
                </template>
            </el-table-column>
            <!--不含税单价金额-->
            <el-table-column prop="quotationAmount" label="不含税单价金额" header-align="center" width="100">
                <template scope="scope">
                    <el-input size="mini"  v-if="!isShow" v-model.number="scope.row.quotationAmount"  :disabled="formInline.isTaxName=='含税'"  @change="inputQuotationAmount(scope.$index, scope.row,$event)"></el-input>
                    <el-input size="mini" v-else v-model.number="scope.row.quotationAmount" :disabled="isTaxShow!=2" @change="inputQuotationAmount(scope.$index, scope.row,$event)"></el-input>
                </template>
            </el-table-column>
            <!--新增税率字段-->
            <el-table-column  label="税率(%)" header-align="center" width="150" prop="taxRate">
                <template scope="scope">
                    <el-select size="mini" clearable  v-model="scope.row.taxRate" placeholder="请选择" @change="inputTaxRate(scope.$index, scope.row,$event)" v-if="!taxDisabled">
                        <el-option v-for="(taxR,index) in taxData" :key="index" :label="taxR.tax" :value="taxR.tax">
                        </el-option>
                    </el-select>
                    <el-input size="mini"  v-model="scope.row.taxRate" disabled v-else></el-input>
                </template>
            </el-table-column>
            <el-table-column prop="quantityAvailable" label="可供数量" header-align="center" width="100">
                <template scope="scope">
                    <el-input size="mini"  v-model.number="scope.row.quantityAvailable" @change="inputQuantityAvailable(scope.$index, scope.row,$event)"></el-input>
                </template>
            </el-table-column>
            <el-table-column prop="moq" label="MOQ" header-align="center" width="100">
                <template scope="scope">
                    <el-input size="mini"  v-model.number="scope.row.moq" placeholder=""  @change="inputMOQ(scope.$index, scope.row,$event)"></el-input>
                </template>
            </el-table-column>
            <el-table-column prop="deliveryCycle" label="交货周期(天)" header-align="center" width="100">
                <template scope="scope">
                    <el-input size="mini"  v-model.number="scope.row.deliveryCycle" placeholder=""  @change="inputDeliveryCycle(scope.$index, scope.row,$event)"></el-input>
                </template>
            </el-table-column>
            <el-table-column prop="quotationExplain" label="说明" header-align="center" width="100">
                            <template scope="scope">
                                <el-input size="mini"  v-model.number="scope.row.quotationExplain" placeholder=""></el-input>
                            </template>
            </el-table-column>
        </el-table>
        <!--导入的弹框-->
        <el-dialog title="导入备件信息" id="LeadIngInMark" :visible.sync="leadIngInVisible" size="tiny" :lock-scroll="false">
            <el-upload class="upload-demo"  :action="action" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" :on-preview="handlePreview" :on-remove="handleRemove" :file-list="fileList" :before-upload="beforeAvatarUpload" :on-success="handleAvatarSuccess">
                <el-button size="mini" type="danger">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">只能上传excel文件</div>
            </el-upload>
        </el-dialog>
    </div>
</template>


<script>

    export default {
        data() {
            return {
                labelWidth:"80px",
                labelWidth100:"100px",
                labelWidth120:"120px",
                taxDisabled:false,
                // 查询表单
                formInline:{
                    id:"",
                    totalQuantityQuoted:'',
                    totalQuotedPrice:'',
                    totalQuotedTaxPrice:'',
                    quotationNum:'',
                    createTime:'',
                    bidder:'',
                    legalPersonId:"",
                    legalPersonCode:"",
                    legalPersonName:"",
                    vendor:"",
                    vendorCode:"",
                    biddingType:"",
                    currencyCode:"",
                    isTax:"",
                    isTaxName:"",
                    startTime:"",
                    endTime:"",
                    quantityAvailable:"",
                    legalPersonNameList:[]
                },
                legalPersonDropDown:[],
                loading:false,
                inquiryDetailsData: [],// 待报价明细表格
                supplierDetails:[],// 待报价供应商明细
                selectDropdown:[],  // 下拉列表的值
                qObjDropDownValue:[],    //报价对象下拉列表
                spareData:[],    // 选择备件弹窗
                taxData:[],//税率列表
                formLabelWidth:"90",
                // 选择备件弹窗的 分页
                // isPaging:true,
                selectSparePartsVisible:false,   //选择备件弹窗
                selectSparePartsForm:{
                    spareCode:"",
                    spareName:""
                },

                // 选择供应商弹窗的  分页
                selectSuppliersVisible:false,
                selectSuppliersForm:{
                    supplierCode:"",
                    supplierName:""
                },
                supplierData:[], //新增供应商弹框中，供应商的信息
                providerList:[],//新增供应商弹框中，选中的供应商的信息
                supplierType:1,

                leadIngInVisible:false,   //导入弹窗
                action:"",
                fileList:[],

                isTaxShow:"",//判断含税与否
                isShow:false,
                isNum:1,
                
                //权限
                powerFlag:false   //不是业务合作人员
            };
        },
        computed:{
            identity(){
                return this.$store.state.identity;
            }
        },
        watch:{
            identity(){
                var _this=this;
                if(_this.identity == 2){
                    _this.powerFlag = true;   //是业务合作人员
                    _this.getVendorCode();  //获取当前登录用户对应的供应商
                }else if(_this.identity == 1){
                    _this.legalPersonDropDownValue();
                }
            }
        },
        //进入页面立即运行此方法
        mounted: function () {
            var _this = this;
            _this.$store.commit('currentActive', 'Quotation');
            _this.createInquerySheetDropdownValue();

            _this.formInline.quotationNumber=_this.$route.query.quotationNumber;
            // 上传地址
            _this.action=_this.procurement_service+"quotation/InquiryIntroduction";

            if(_this.identity == 2){
                _this.powerFlag = true;   //是业务合作人员
                _this.getVendorCode();  //获取当前登录用户对应的供应商
            }else if(_this.identity == 1){
                _this.legalPersonDropDownValue();
            }

            _this.seeQuotation();  //进入页面直接 查看报价单列表
            _this.getTaxData();//获取税率
        },
        methods: {
              // 获取当前登录用户对应的供应商
            getVendorCode(){     //报价单位
                var _this = this;
                $.ajax({
                    type:'GET',
                    url:_this.procurement_service+"quotation/findByVendorName",
                    cache:false,
                    success:function(data){
                        if(data.success){
                            _this.formInline.vendorid = data.data[0].id;
                            _this.formInline.vendorCode = data.data[0].partnerCode;
                            _this.formInline.vendor = data.data[0].partnerName;
                            
                            _this.quotationObj();//报价对象下拉列表
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            // 报价对象下拉列表
            quotationObj(){ 
                var _this = this;
                var tmp = {id:_this.formInline.vendorid};
                $.ajax({
                    url:_this.metadata_service+'partner/queryLegalPerson',
                    type:'POST',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:'application/json;charset=utf-8',
                    success:function(data){
                        if(data.success){
                            _this.qObjDropDownValue = data.data;
                            if(_this.qObjDropDownValue && _this.qObjDropDownValue.length==1){
                                _this.formInline.legalPersonId = _this.qObjDropDownValue[0].id;
                                _this.formInline.legalPersonCode = _this.qObjDropDownValue[0].legalPersonCode;
                                _this.formInline.legalPersonName = _this.qObjDropDownValue[0].legalPersonName;
                            }
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            // 选择报价对象
            selectedQObj(){
                var _this = this;
                for(var i=0;i<_this.qObjDropDownValue.length;i++){
                    if(_this.formInline.legalPersonCode == _this.qObjDropDownValue[i].legalPersonCode){
                        _this.formInline.legalPersonId = _this.qObjDropDownValue[i].id;
                        _this.formInline.legalPersonName = _this.qObjDropDownValue[i].legalPersonName;
                    }
                }
            },
            //判断是含税还是不含税
            changeTax(){
                var _this=this;
                //console.log(_this.formInline.isTaxName)
                if(_this.isNum==1){
                    if(_this.formInline.isTaxName==1){
                        _this.isTaxShow=1;
                    }else if(_this.formInline.isTaxName==2){
                        _this.isTaxShow=2;
                    }
                    _this.isNum++;
                }else{
                    _this.isShow=true;
                    if(_this.formInline.isTaxName==1){
                        _this.isTaxShow=1;
                    }else if(_this.formInline.isTaxName==2){
                        _this.isTaxShow=2;
                    }
                }
                // debugger
               //选择含不含税计算总金额
                var arr=_this.inquiryDetailsData;
                if(_this.formInline.isTaxName == 2 || _this.formInline.isTaxName=="不含税"){
                    _this.formInline.totalQuotedTaxPrice=0;
                    _this.formInline.totalQuotedPrice=0;
                    for(var i=0;i<arr.length;i++){
                        //不含税
                        if(_this.formInline.isTaxName == 2){
                            arr[i].quotationAmount=null;
                        }
                        arr[i].includingTaxPrice=null;
                        arr[i].taxRate=null;
                        _this.taxDisabled=true;
                        if(_this.inquiryDetailsData[i].quotationAmount){
                            _this.formInline.totalQuotedPrice +=_this.inquiryDetailsData[i].quotationAmount * _this.inquiryDetailsData[i].quotedQuantity;
                            // console.log(_this.formInline.totalQuotedPrice,"选择含不含税")
                        }
                    }
                    _this.formInline.totalQuotedPrice=_this.formInline.totalQuotedPrice.toFixed(8);
                }else if(_this.formInline.isTaxName==1 || _this.formInline.isTaxName=="含税"){
                    //含税
                        //if(_this.formInline.isTaxName == 1){
                            _this.formInline.totalQuotedTaxPrice=0;
                            _this.formInline.totalQuotedPrice=0;
                        //}
                    setTimeout(function(){
                        for(var i=0;i<_this.inquiryDetailsData.length;i++){
                            if(arr[i].includingTaxPrice==null){
                                arr[i].quotationAmount=null;
                            }
                            _this.taxDisabled=false;
                            _this.formInline.totalQuotedTaxPrice +=_this.inquiryDetailsData[i].includingTaxPrice * _this.inquiryDetailsData[i].quotedQuantity;
                            _this.formInline.totalQuotedPrice +=_this.inquiryDetailsData[i].quotationAmount * _this.inquiryDetailsData[i].quotedQuantity;
                            // console.log(i,_this.formInline.totalQuotedPrice,"选择含不含税")
                        }
                        _this.formInline.totalQuotedTaxPrice=_this.formInline.totalQuotedTaxPrice.toFixed(8);
                        _this.formInline.totalQuotedPrice=_this.formInline.totalQuotedPrice.toFixed(8);
                    },0);

                }
            },
            //获取税率列表
            getTaxData(){
                var _this=this;
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service+"tax/findTaxDuplicateRemovalList",
                    cache: false,
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            _this.taxData=data.data;
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                });
            },
            //报价生效日期
            selectedStartTime(val){
                var _this=this;
                _this.formInline.startTime = val;
                if(_this.formInline.endTime && val > _this.formInline.endTime){
                    _this.common.errorTip("报价生效日期不能大于报价失效日期");
                    _this.formInline.startTime = "";
                };
            },
            //报价失效日期
             selectedEndTime(val){
                var _this=this;
                _this.formInline.endTime = val;
                if(_this.formInline.startTime && val < _this.formInline.startTime){
                    _this.common.errorTip("报价失效日期不能小于报价生效日期");
                    _this.formInline.endTime = "";
                };
            },
            // 修改的接口  修改后保存/提交
            updateData(inquiryStatus){
                var _this = this;
                if(_this.formInline.isTaxName=="含税" || _this.formInline.isTaxName==1){
                    //含税
                    _this.formInline.isTax=1;
                    console.log("含税")
                }else if(_this.formInline.isTaxName=="不含税" || _this.formInline.isTaxName==2){
                    //不含税
                    _this.formInline.isTax=2;
                }
                var tmp = {legalPersonName:_this.formInline.legalPersonName,vendorCode:_this.formInline.vendorCode,vendor:_this.formInline.vendor,totalQuantityQuoted:_this.formInline.totalQuantityQuoted,totalQuotedPrice:_this.formInline.totalQuotedPrice,totalQuotedTaxPrice:_this.formInline.totalQuotedTaxPrice,exchangeRate:_this.formInline.exchangeRate,currencyCode:_this.formInline.currencyCode,quantityAvailable:_this.quantityAvailable,quotationNumber:_this.formInline.quotationNumber,biddingStatus:inquiryStatus,createTime:_this.formInline.createTime,bidder:_this.formInline.bidder,legalPersonId:_this.formInline.legalPersonId,biddingType:_this.formInline.biddingType,isTax:_this.formInline.isTax,startTime:_this.formInline.startTime,endTime:_this.formInline.endTime,quotationItem:_this.inquiryDetailsData,};
                $.ajax({
                    url:_this.procurement_service+'quotation/update',
                    type:'POST',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:'application/json;charset=utf-8',
                    success:function(data){
                        if(data.success){
                            _this.common.successTip("操作成功！");
                            if(inquiryStatus==20){
                                _this.$router.push("/quotationSheet");
                            }
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            //含税不含税验证
            validTax(){
                var _this=this;
                var arr=_this.inquiryDetailsData;
                //校验数字
                for(var i=0;i<arr.length;i++){
                    if(arr[i].quantityAvailable==null || arr[i].quantityAvailable==""){
                        _this.common.errorTip("可供数量不能为空");
                        return false;
                    }
                    if(arr[i].moq==null || arr[i].moq==""){
                        _this.common.errorTip("MOQ不能为空");
                        return false;
                    }
                    if(arr[i].deliveryCycle==null || arr[i].deliveryCycle==""){
                        _this.common.errorTip("交货周期不能为空");
                        return false;
                    }
                    if(!(/^(\-?)(\d+)$/.test(arr[i].quantityAvailable))){
                        _this.common.errorTip("可供数量必须是数字");
                        return false;
                    }
                    if(!(/^(\-?)(\d+)$/.test(arr[i].moq))){
                        _this.common.errorTip("MOQ必须是数字");
                        return false;
                    }
                    if(arr[i].moq<=0){
                        _this.common.errorTip("MOQ必须大于0");
                        return false;
                    }
                    if(!(/^(\-?)(\d+)$/.test(arr[i].deliveryCycle))){
                        _this.common.errorTip("交货周期必须是数字");
                        return false;
                    }
                }
                if (_this.isTaxShow == 1) {
                    //含税，税率是必须的
                    for(var i=0;i<arr.length;i++){
                        if(arr[i].taxRate!=0){
                           if(arr[i].taxRate==null || arr[i].taxRate==""){
                               _this.common.errorTip("税率不允许为空");
                               return false;
                           }
                       }else if(arr[i].includingTaxPrice==null || arr[i].includingTaxPrice==""){
                            _this.common.errorTip("含税单价不允许为空");
                            return false;
                        }else if(arr[i].quotationAmount==null || arr[i].quotationAmount==""){
                            _this.common.errorTip("不含税单价不允许为空");
                            return false;
                        }else if(!(/^\d+(\.\d+)?$/.test(arr[i].includingTaxPrice))){
                            _this.common.errorTip("含税单价必须是数字");
                            return false;
                        }else  if(!(/^\d+(\.\d+)?$/.test(arr[i].quotationAmount))){
                            _this.common.errorTip("不含税单价必须是数字");
                            return false;
                        }
                    }
                    return true;
                }else{
                    //不含税，税率可无
                    for(var i=0;i<arr.length;i++){
                        if(arr[i].quotationAmount==null || arr[i].quotationAmount==""){
                            _this.common.errorTip("不含税单价不允许为空");
                            return false;
                        }else  if(!(/^\d+(\.\d+)?$/.test(arr[i].quotationAmount))){
                            _this.common.errorTip("不含税单价必须是数字");
                            return false;
                        }
                    }
                    return true;
                }
            },
            //保存按钮
            save(inquiryStatus){
                var _this = this;
                var validTaxSave=_this.validTax();
                if(validTaxSave){
                    _this.updateData(inquiryStatus);
                }
            },
            //提交按钮
            onSubmit(inquiryStatus){
                var _this = this;
                var validTaxSave=_this.validTax();
                if(validTaxSave){
                    _this.updateData(inquiryStatus);
                }
            },
            legalPersonDropDownValue(){  //法人名称下拉列表值
                var _this = this;
                $.ajax({
                    type:'GET',
                    url:_this.procurement_service+"legalPerson/ofCurrentUser",
                    cache:false,
                    success:function(data){
                        if(data.success){
                            _this.legalPersonDropDown = data.data;
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            seeQuotation(){   //查看报价单列表
                var _this =this;
                var tmp = {quotationNumber:_this.formInline.quotationNumber};
                $.ajax({
                    url:_this.procurement_service+'quotation/see',
                    type:'POST',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:'application/json;charset=utf-8',
                    success:function(data){
                        //console.log(data);
                        if(data.success){
                            _this.formInline=data.data[0];
                            if(_this.formInline.isTax==1){
                                _this.isTaxShow=1;
                            }else{
                                _this.isTaxShow=2;
                            }
                            _this.formInline.inquiryStatus=data.data[0].biddingStatus;
                            _this.inquiryDetailsData=data.data[0].quotationItem;
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            createInquerySheetDropdownValue(){ //下拉列表的值
                var _this =this;
                var tmp = ["type","isTax","currencyCode"];
                $.ajax({
                    type:'POST',
                    url:_this.procurement_service+'procurement/getPullDownList',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:"application/json;charset=utf-8",
                    success: function(data){
                        if(data.success){
                            _this.selectDropdown=data.data;
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                });
            },
            // 下拉列表选择币别
            selectCurrencyCode(){
                var _this=this; 
                // 表格中的币别显示汉字
                for(var i=0;i<_this.selectDropdown.currencyCode.length;i++){
                    if(_this.formInline.currencyCode == _this.selectDropdown.currencyCode[i].value){
                        _this.formInline.currencyCodeWord = _this.selectDropdown.currencyCode[i].label;
                    }
                }
                for(var i=0;i<_this.inquiryDetailsData.length;i++){
                    _this.inquiryDetailsData[i].currencyCode=_this.formInline.currencyCode;
                    _this.inquiryDetailsData[i].currencyCodeWord=_this.formInline.currencyCodeWord;
                }
            },
            //待报价明细 每行的删除按钮
            handleDel(index,rows){
                rows.splice(index,1);
            },
            // 待报价明细  导入按钮
            leadingInMask(){
                var _this=this;
                _this.leadIngInVisible = true;
                _this.fileList=[];
            },
            //上传之前的钩子
            beforeAvatarUpload(file) {
                const isExcel2007 = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
                const isExcel2003 = file.type === 'application/vnd.ms-excel';
                if (!isExcel2007 && !isExcel2003) {
                    this.$message.error('只能上传excel文件!');
                }
                return isExcel2007 || isExcel2003 ;
            },
            //文件上传成功时的钩子
            handleAvatarSuccess(res, file){
                var _this=this;
                if(res.success){
                    _this.common.successTip("上传成功！");
                    for(var i=0;i<res.data.length;i++){
                        _this.inquiryDetailsData.push({
                            subclass:res.data[i].subclass,
                            spareCoding:res.data[i].code,
                            spareName:res.data[i].name,
                            standard:res.data[i].standard,
                            measurementUnit:res.data[i].unit,
                            MOQ:res.data[i].volumeProductionMOQ
                        });
                    }
                    _this.LeadIngInVisible = false;
                }else{
                    _this.fileList=[];
                    _this.common.errorTip(res.errorMessage);
                }
            },
            handleRemove(file, fileList) {
                // console.log(file, fileList);
            },
            handlePreview(file) {
                // console.log(file);
            },

            // 待报价明细 新增按钮
            addSpare(){
                var _this =this;
                _this.selectSparePartsVisible=true;
            },
            // MOQ
            inputMOQ(index,row){
                var _this=this;
                if(typeof(row.moq)!="number"){
                    _this.common.errorTip("MOQ只能为数字！");
                }else if(row.moq==0){
                    _this.common.errorTip("MOQ必须大于零！");
                }
            },
            // 输入可供数量
            inputQuantityAvailable(index,row){
                var _this=this;
                if(typeof(row.quantityAvailable)!="number"){
                    _this.common.errorTip("报价数量只能为数字！");
                }else if(row.quantityAvailable==0){
                    _this.common.errorTip("报价数量必须大于零！");
                }
            },
            // 输入不含税单价金额
            inputQuotationAmount(index,row){
                var _this=this;
                if(typeof(row.quotationAmount)!="number"){
                    _this.common.errorTip("不含税单价金额只能为数字！");
                }else if(row.quotationAmount==0){
                    _this.common.errorTip("不含税单价金额必须大于零！");
                }
                if(row.quotationAmount != "" || row.quotationAmount != null){
                   /* if(row.taxRate!=null){
                        row.includingTaxPrice=(row.quotationAmount*(1+row.taxRate/100)).toFixed(8);//计算含税单价金额=不含税金额＊（1+税率）
                    }*/
                    _this.formInline.totalQuotedPrice=0;
                    setTimeout(function(){
                        for(var i=0;i<_this.inquiryDetailsData.length;i++){
                            _this.formInline.totalQuotedPrice +=_this.inquiryDetailsData[i].quotationAmount * _this.inquiryDetailsData[i].quotedQuantity;
                        }
                        _this.formInline.totalQuotedPrice=_this.formInline.totalQuotedPrice.toFixed(8);
                    },0);
                }else{
                    _this.common.errorTip("单价不能为空");
                }
            },
            //输入含税金额
            inputTaxPrice(index,row){
                var _this=this;
                if(row.includingTaxPrice != "" || row.includingTaxPrice != null){
                    if(row.taxRate!=null){
                        row.quotationAmount = (row.includingTaxPrice / (1 + row.taxRate / 100)).toFixed(8);//计算不含税单价金额=含税单价金额/（1+税率）
                    }
                    _this.formInline.totalQuotedTaxPrice=0;
                    _this.formInline.totalQuotedPrice=0;
                    setTimeout(function(){
                        for(var i=0;i<_this.inquiryDetailsData.length;i++){
                            _this.formInline.totalQuotedTaxPrice +=_this.inquiryDetailsData[i].includingTaxPrice * _this.inquiryDetailsData[i].quotedQuantity;
                            _this.formInline.totalQuotedPrice +=_this.inquiryDetailsData[i].quotationAmount * _this.inquiryDetailsData[i].quotedQuantity;
                        }
                        _this.formInline.totalQuotedTaxPrice=_this.formInline.totalQuotedTaxPrice.toFixed(8);
                        _this.formInline.totalQuotedPrice=_this.formInline.totalQuotedPrice.toFixed(8);
                    },0);
                }else{
                    _this.common.errorTip("单价不能为空");
                }
            },
            //选择税率
            inputTaxRate(index,row){
                var _this=this;
                //if(typeof row.includingTaxPrice!="undefined" && typeof row.quotationAmount!="undefined"){
                    //初进入页面
                    if(_this.formInline.isTaxName=="含税"){
                        //含税
                        if(row.includingTaxPrice!=null){
                            row.quotationAmount = (row.includingTaxPrice / (1 + row.taxRate / 100)).toFixed(8);//计算不含税单价金额=含税单价金额/（1+税率）
                        }
                    }/*else if(_this.formInline.isTaxName=="不含税"){
                        //不含税
                        if(row.quotationAmount!=null){
                            row.includingTaxPrice=(row.quotationAmount*(1+row.taxRate/100)).toFixed(8);//计算含税单价金额=不含税金额＊（1+税率）
                        }
                    }*/
                    //改变是否含税以后
                    if(_this.formInline.isTaxName==1){
                        if(row.includingTaxPrice!=null){
                            //含税
                            row.quotationAmount = (row.includingTaxPrice / (1 + row.taxRate / 100)).toFixed(8);//计算不含税单价金额=含税单价金额/（1+税率）
                        }
                        /*_this.formInline.totalQuotedPrice=0;
                        setTimeout(function(){
                            for(var i=0;i<_this.inquiryDetailsData.length;i++){
                                _this.formInline.totalQuotedPrice +=_this.inquiryDetailsData[i].quotationAmount * _this.inquiryDetailsData[i].quotedQuantity;
                            }
                            _this.formInline.totalQuotedPrice=_this.formInline.totalQuotedPrice.toFixed(8);
                        },0);*/
                    }
                     _this.formInline.totalQuotedPrice=0;
                    setTimeout(function(){
                        for(var i=0;i<_this.inquiryDetailsData.length;i++){
                            _this.formInline.totalQuotedPrice +=_this.inquiryDetailsData[i].quotationAmount * _this.inquiryDetailsData[i].quotedQuantity;
                        }
                        _this.formInline.totalQuotedPrice=_this.formInline.totalQuotedPrice.toFixed(8);
                    },0);
                    /*else if(_this.formInline.isTaxName==2){
                        //不含税
                        if(row.quotationAmount!=null){
                            row.includingTaxPrice=(row.quotationAmount*(1+row.taxRate/100)).toFixed(8);//计算含税单价金额=不含税金额＊（1+税率）
                        }
                    }*/
                //}

            },
            // 交货周期（天）
            inputDeliveryCycle(index,row){
                var _this=this;
                if(typeof(row.deliveryCycle)!="number"){
                    _this.common.errorTip("交货周期（天）只能为数字！");
                }else if(row.deliveryCycle==0){
                    _this.common.errorTip("交货周期（天）必须大于零！");
                }
            }
        }
    }
</script>
<style scoped>
    .el-select .el-tag{
        margin: 0;
    }
    .el-select__tags .el-select__input {
        display: none;
    }
    .main-right .el-pagination{
        margin-top: 0;
    }
</style>